<template>
  <div class="mini-booking-item">
    <div class="item" v-for="item in dataList" :key="item.id">
      <div class="title">
        {{ type === "sights" ? item.sightsName : item.hotelName }}
      </div>
      <div class="option">
        <div class="status">
          <el-tag size="mini" :type="switchStatusStr(item.status)">{{
            switchStatus(item.status)
          }}</el-tag>
        </div>
        <div class="detail" @click="detail(item.id)" v-show="!other">详情</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "MiniBookingItem",
  props: {
    dataList: {
      type: Array,
      default: () => [],
    },
    type: {
      type: String,
      default: "",
    },
    other: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    // 判断状态
    switchStatus(status) {
      switch (status) {
        case 0:
          return "已取消";
        case 1:
          return "已预约";
        case 2:
          return "已使用";
        case -1:
          return "已过期";
      }
    },
    // 判断状态字符
    switchStatusStr(status) {
      switch (status) {
        case 0:
          return "warning";
        case 1:
          return "success";
        case 2:
          return "primary";
        case -1:
          return "danger";
      }
    },
    // 详情
    detail(id) {
      if (this.type === "sights") {
        this.$router.push(`/booking/sights/detail/${id}`);
      } else if (this.type === "hotel") {
        this.$router.push(`/booking/hotel/detail/${id}`);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.mini-booking-item {
  .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
    border-bottom: 1px solid #ccc;
    .title {
      margin-left: 10px;
      width: 50%;
      font-size: 15px;
      text-align: left;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .option {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .status {
        margin-right: 14px;
      }
      .detail {
        margin-right: 10px;
        color: #999;
        font-size: 14px;
        cursor: pointer;
      }
    }
  }
}
</style>